// mircoApp/merchant_offer_discounts/index/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_shop_commission: "",
    cashier_shop_commission: "",
    diy_name:"",
    store_id:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.store_id = options.store_id||'';
    this.setData({
      diy_name:wx.getStorageSync('yz_basic_info').plugin_setting?.merchant_offer_discounts?.diy_name
    })
    wx.setNavigationBarTitle({
      title: this.data.diy_name,
    })
    this.getData();
  },
  onChange(e){
    let field = e.currentTarget.dataset.field;
    this.setData({
      [field]:e.detail
    })
  },
  getData(){
    let json = {
      store_id: this.data.store_id * 1
  }
  app._postNetWork({
    url:app.getNetAddresss("plugin.merchant-offer-discounts.frontend.controllers.index.index"),
    data:json,
    success:resdata=>{
      let {result,msg,data} = resdata.data;
      if(result){
          this.setData({
            store_shop_commission:data.store_shop_commission * 1,
            cashier_shop_commission:data.cashier_shop_commission * 1
          })
      }else{
        app.tips(msg);
      }
    }
  })
  },
  submit() {
    let json = {
        store_id: this.data.store_id * 1,
        store_shop_commission: this.data.store_shop_commission * 1,
        cashier_shop_commission: this.data.cashier_shop_commission * 1,
    }
    app._postNetWork({
      url:app.getNetAddresss("plugin.merchant-offer-discounts.frontend.controllers.index.update-store-setting"),
      data:json,
      success:resdata=>{
        let {result,msg} = resdata.data;
        app.tips(msg);
        if(result){
          this.getData();
        }
      }
    })
   
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})